package Search.search2016;

public class BinarySearch {

	public static void main(String[] args) {
		int[] array={1,2,4,5,25,63,72,81};
        System.out.println(binarySearch(array,5));
	}
	public static int binarySearch(int[] array,int num){
		if(array==null||array.length==0){
			return -1;
		}
		int low = 0;
		int high = array.length-1;
		while(low<=high){
			int mid=(low+high)/2;
			if(num==array[mid]){
				return mid;
			}
			else if(num>array[mid]){
				low = mid+1;
			}
			else{
				high=mid-1;
			}
		}
		return -1;
	}

}
